# ---------- ---------- ---------- ---------- ---------- ----------
#
# GNUsocial maintenance tasks
#
# ---------- ---------- ---------- ---------- ---------- ----------

_PathToGnusocial=../gnusocial.no/
PathToGnusocial=$(if $(p),$(p),$(_PathToGnusocial))
PathToBackupScript=./plugins/backup.sh
TimeLimit=$(if $(t),$(t),`date +%F`)

target: help

# ---------- ---------- ---------- ---------- ---------- ----------
#NOTE: The recipes follow:
# ---------- ---------- ---------- ---------- ---------- ----------

.PHONY: testing
testing:
	@echo testing
	@echo $(_PathToGnusocial)
	@echo $(PathToGnusocial)
	@echo $(PathToBackupScript)
	@echo done

.PHONY: help
help:
	@echo use init, backup, or maintenance...

.PHONY: dump
dump:
	@./src/backups.sh $(PathToGnusocial)

.PHONY: start
start:
	@echo Starting daemons...
	$(PathToGnusocial)scripts/startdaemons.sh
	@echo done

.PHONY: stop
stop:
	@echo Stopping daemons...
	$(PathToGnusocial)scripts/stopdaemons.sh
	@echo done

.PHONY: restart
restart:
	@echo Restarting daemons...
	$(PathToGnusocial)scripts/stopdaemons.sh
	$(PathToGnusocial)scripts/startdaemons.sh
	@echo done

.PHONY: basic
basic:
	@echo Running quick maintenance...
	$(PathToGnusocial)scripts/stopdaemons.sh
	php $(PathToGnusocial)scripts/upgrade.php
	@echo next
	php $(PathToGnusocial)scripts/checkschema.php
	php $(PathToGnusocial)scripts/updateurls.php
	$(PathToGnusocial)scripts/startdaemons.sh
	@echo done

.PHONY: gc
gc:
	@php $(PathToGnusocial)plugins/StoreRemoteMedia/scripts/removeRemoteMedia.php --all --limit $(TimeLimit)
	@php $(PathToGnusocial)scripts/delete_orphan_files.php --yes
